package com.web.a.weba.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.example.demob.service.TestService;
import com.example.democ.service.UserService;
import com.web.a.weba.filter.TimeRankFilter;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;


@RestController
public class TestController {

   static ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
   static {
       threadPoolTaskExecutor.setCorePoolSize(40);
       threadPoolTaskExecutor.setMaxPoolSize(60);
       threadPoolTaskExecutor.initialize();
   }


    @PostConstruct
    private void initTest(){

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int i = new Random().nextInt(3);
                if (i < 1) {
                    try {
                        userService.testA();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else if (i < 2) {
                    try {
                        userService.testB();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else if (i < 3) {
                    try {
                        userService.testC();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        Thread threadOne=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    threadPoolTaskExecutor.submit(runnable);
                }
            }
        });
        threadOne.start();
    }


    @Reference
    private TestService testService;

    @Reference
    private UserService userService;


    @RequestMapping("/test")
    public String test(){
         String test = userService.test();
        return testService.test();
    }

    @RequestMapping("/testUser")
    public String testUser(){
        return userService.test();
    }


    @RequestMapping("/startJob")
    public void startJob()  {

    }

}
